package com.poisonh.unifiedauth.dialog;

import android.annotation.SuppressLint;
import android.app.DialogFragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;

import com.poisonh.unifiedauth.R;
import com.poisonh.unifiedauth.ui.LoginActivity;
import com.poisonh.unifiedauth.utils.ActivityStack;
import com.poisonh.unifiedauth.utils.PreferencesUtils;

/**
 * 退出登录
 * Created by PoisonH on 2016/8/4.
 */
public class SignOutDialogFragment extends DialogFragment implements View.OnClickListener
{
    private Button mBtnCancel;
    private Button mBtnSignOut;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        @SuppressLint("InflateParams")
        View view = inflater.inflate(R.layout.layout_dialog_signout, null);
        return view;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState)
    {
        super.onViewCreated(view, savedInstanceState);
        mBtnCancel = (Button) view.findViewById(R.id.btn_cancel);
        mBtnSignOut = (Button) view.findViewById(R.id.btn_signout);
        mBtnCancel.setOnClickListener(this);
        mBtnSignOut.setOnClickListener(this);
    }

    @Override
    public void onClick(View v)
    {
        switch (v.getId())
        {
            case R.id.btn_cancel:
                this.dismiss();
                break;
            case R.id.btn_signout:
                if (PreferencesUtils.deleteValue(getActivity(), "ID"))
                {
                    //  ActivityStack.getAppManager().finishAllActivity();
                    //将视频审核状态改为false，防止用户切换账号，请求不到用户视频审核状态。
                    PreferencesUtils.putBoolean(getActivity(), "VideoState", false);
                    PreferencesUtils.deleteValue(getActivity(), "ID");
                    ActivityStack.getAppManager().exit();
                    this.dismiss();
                    startActivity(new Intent(getActivity(), LoginActivity.class));
                }
                break;
        }
    }
}
